<?php

/**
 * 
 *
 * @version $Id: start.inc.php,v 1.5 2004/11/10 18:47:15 phppc Exp $
 * @copyright 2003 
 **/

$start = $this->fun_sg2var("start");
$start = $this->uf_form_conf_def($start,array("show","act_news","act_user"),"show");
$this->module_new_value["action"] = "start";

if ($start == "show") {
	$erg = $this->db_abfrage_q("SELECT news_id,n_title,n_text,user_id FROM ".$this->config["prefix"]."main WHERE active = \"0\"");
	$anzahl_n = 0;
	$start_news_ones = '';
	$start_user = '';
	while($db_news = $this->db_abfrage_fetch($erg)){
		$db_news["n_title"] = stripslashes($db_news["n_title"]);
		$actn_link = $this->fun_make_link("admin.php","start=act_news&news_id=".$db_news["news_id"]."");
		list($n_text, $shorter, $n_preview) = $this->fun_lim_news($db_news["n_text"],$this->db_config["start_n_preview"]);
		$this->tpl_load("start_news_one","admin/");
		$this->tpl_replace_vars(array("actn_link" => $actn_link, "n_title" => $db_news["n_title"], "n_preview" => $n_preview, "n_user" => $this->user_array[$db_news["user_id"]]["user_name"], "news_id" => $db_news["news_id"]));
		$start_news_ones .= $this->tpl_output();
		$anzahl_n++;
	} // while
	$erg = $this->db_abfrage_q("SELECT * FROM ".$this->config["db_table_user"]." WHERE act_key != \"\"");
	$anzahl_u = 0;
	while($db_user = $this->db_abfrage_fetch($erg)){
		$this->tpl_load("start_user_one","admin/");
		$this->tpl_replace_vars(array("user_name" => $db_user["user_name"]));
		$start_user_ones .= $this->tpl_output("user_name");
		$anzahl_u++;
	} // while
	if($anzahl_n >= 1)  {
		$hidden_array["start"] = "act_news";
		$hidden_array["act_news"] = "act";
		$hidden_array["multiple_news"] = 1;
		$hidden_form = $this->uf_create_hidden_form($hidden_array);
		$this->tpl_load("start_news","admin/");
		$this->tpl_replace_vars(array("hidden_form" => $hidden_form, "start_news_ones" => $start_news_ones));
		$start_news = $this->tpl_output();
	}else $this->message_red[] = 15;
	if($anzahl_u >= 1) {
		$this->tpl_load("start_user","admin/");
		$this->tpl_replace_vars(array("start_user_ones" => $start_user_ones));
		$start_user = $this->tpl_output();
	}
	else $this->message_red[] = 16;
	$this->tpl_load("start","admin/");
	$this->tpl_replace_vars(array("start_news" => $start_news,"start_user" => $start_user));
	$nc_main = $this->tpl_output();
}elseif ($start == "act_news"){
	if ($this->perm_array["news_act"] == 1) {
		$act_news = $this->fun_sg2var("act_news");
		$act_news = $this->uf_form_conf_def($act_news,array("show","act","deny"),"show");
		if ($act_news == "show") {
		    $news = $this->db_abfrage_az("SELECT ".$this->config["prefix"]."main.news_id AS news_id, ".$this->config["prefix"]."main.n_title AS n_title, ".$this->config["prefix"]."main.n_text AS n_text, ".$this->config["prefix"]."main.links AS links, ".$this->config["prefix"]."main.kat AS kat_id, ".$this->config["prefix"]."main.user_id AS user_id, ".$this->config["prefix"]."main.time_start AS time_start, ".$this->config["prefix"]."main.time_end AS time_end, ".$this->config["prefix"]."main.anzahl_coms AS anzahl_coms, ".$this->config["db_table_user"].".user_name AS user_name, ".$this->config["db_table_user"].".email AS email, ".$this->config["prefix"]."kat.name AS kat_name, ".$this->config["prefix"]."kat.image AS kat_image
			FROM ".$this->config["prefix"]."main LEFT JOIN ".$this->config["db_table_user"]." ON ".$this->config["prefix"]."main.user_id = ".$this->config["db_table_user"].".id LEFT JOIN ".$this->config["prefix"]."kat ON (".$this->config["prefix"]."main.kat = ".$this->config["prefix"]."kat.id) WHERE ".$this->config["prefix"]."main.active=\"0\" AND ".$this->config["prefix"]."main.news_id = \"".$_GET["news_id"]."\"");
			$news_tpl = $nc_n->one_news($news,"preview");
			eval ("\$nc_main = \$tpl_nc->ausgabe1(\"".$this->tpl_load("act_news","admin/")."\");");
			$act_link = $this->fun_make_link("admin.php","action=start&start=act_news&act_news=act&act_news_id=$news_id");
			$name_array[1] = "action";
			$var_array[1] = "start";
			$name_array[2] = "start";
			$var_array[2] = "act_news";
			$name_array[3] = "act_news";
			$var_array[3] = "deny";
			$name_array[4] = "news_id";
			$var_array[4] = $news_id;
			$hidden_fields = $uf->create_hidden_form($name_array,$var_array);
			eval ("\$nc_optional = \$tpl_nc->ausgabe1(\"".$this->tpl_load("act_news_right","admin/")."\");");
		}elseif($act_news == "act") {
			if (isset($_POST["act_news_array"]) OR isset($_GET["act_news_id"])) {
				if($_POST["multiple_news"] == 1) $where_part = $this->uf_create_where_part($_POST["act_news_array"],"news_id");
				else $where_part = "news_id=\"".$_GET["news_id"]."\"";
				$erg = $this->db_abfrage_q("UPDATE ".$this->config["prefix"]."main SET active=\"1\" WHERE $where_part");
				if($erg) $this->message_green[] = 19;	
			}else $this->message_red[] = 1;
			$this->w_leitung["url"] = $this->fun_make_link("admin.php");
			$this->w_leitung["number"] = 9;
		}elseif($act_news == "deny") {
			$_POST = $uf->secure($_POST);
			list($news_text,$user_email,$news_user) = $this->db_abfrage("SELECT ".$this->config["prefix"]."main.n_text,".$this->config["db_table_user"].".email,".$this->config["db_table_user"].".user_name FROM ".$this->config["prefix"]."main LEFT JOIN ".$this->config["db_table_user"]." ON (".$this->config["prefix"]."main.user_id = ".$this->config["db_table_user"].".id) WHERE ".$this->config["prefix"]."main.news_id=\"".$_POST["news_id"]."\"");
			$email_array["%news_text%"] = $news_text;
			$email_array["%administrator%"] = $user["user_name"];
	
			$email_array["%reason%"] = $_POST["reason"];
			send_email($user_email,"gentner@phppc.de","admin_start_act_news_activate_not_email_subject","admin_start_act_news_activate_not_email_message",$email_array);
			$this->message_green[] = 60;
			$this->w_leitung["url"] = $this->fun_make_link("admin.php","action=start");
			$this->w_leitung["number"] = 9;
		}    
	}	
}
 

?>